import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-03-17
 * Time: 20:39
 */
public class Exercise {
    //Arrarys.fill函数
    public static void main(String[] args) {
        int []arr = {8,4,5,1,2};
        Arrays.fill( arr,0,3,99);
        for (int x:arr) {
            System.out.print(x +" ");
        }

    }
    //冒泡排序优化
    public static void bubble( int[]arr){
        for (int i = 0; i < arr.length-1; i++) {
            boolean flg =false;
            for (int j = 0; j < arr.length - i - 1; j++) {
                if( arr[j]>arr[j+1] ) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    flg = true;
                }
            }
            if(!flg){
                return ;
            }
        }
    }
    //二分查找
    public static void main1(String[] args) {
        int []arr = new int[]{1,2,3,4,5,6,7,8};
        System.out.println(Arrays.binarySearch(arr, -8));
    }
    //自定义实现 toString 方法
    public static  String mytoString( int[]arr)
    {
        if(arr == null) {
            return null;
        }
        String s="[";
        for (int i = 0; i < arr.length; i++) {
            if(i<arr.length - 1) {
                s = s + arr[i]  + ",";
            } else {
                s = s+arr[i]+"";
            }
        }
        s= s+"]";
        return s;
    }
    public static void main2(String[] args) {
        int []arr = {5,5,6,7,8,1,2};
        bubble(arr);
        for (int j : arr) {
            System.out.print(j + " ");
        }

    }
}
